﻿

using System;
using System.Configuration;
using System.ServiceModel;
using System.Runtime.Serialization; 
using GH.Northwind.Business;
using GH.Northwind.Business.Interfaces;

namespace GH.Northwind.Client.Common
{
    public class NorthwindHandler
    {
        public static INorthwindSvr GetNorthwindService()
        {
            if (ConfigurationSettings.AppSettings["N-Tier"].ToLower() == "true")
            {
                string northwindBusinessUrl = ConfigurationSettings.AppSettings["NorthwindSvrBusinessUrl"];
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = 1000000;
                binding.ReaderQuotas.MaxDepth = 200; 
                ChannelFactory<INorthwindSvr> channelFactory = new ChannelFactory<INorthwindSvr>(
                    binding,
                    new EndpointAddress(new Uri(northwindBusinessUrl)));
                INorthwindSvr northwindSvr = channelFactory.CreateChannel();
                return northwindSvr;
            }
            else
            {
                return new NorthwindSvr();
            }
        }
    }
}